<!DOCTYPE html>
<html style="width:100%;height:100%;">
<head lang="en">
    <meta charset="UTF-8">
    <title>微信请求列表</title>
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/default/easyui.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/color.css">
    <link type="text/css" rel="stylesheet" href="/resources/easyui/themes/icon.css">
    <link type="text/css" rel="stylesheet" href="/resources/css/yidong.css">
    <script type="text/javascript" src="/resources/easyui/jquery.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="/resources/easyui/locale/easyui-lang-zh_CN.js"></script>
    <script type="text/javascript" src="/resources/easyui/plugin/jquery.cookie.js"></script>
    <script type="text/javascript" src="/resources/js/Util.js"></script>
    <script type="text/javascript">
        $(document).ready(function(){
            var pageSize = $.cookie("pageSize");
            $.cookie("pageNo", 1, {expires:1});
            if(!pageSize) {
                $.cookie("pageSize", 10, {expires:1});
            }
            loadWechatRequestList($.cookie("pageSize"), $.cookie("pageNo"), null, 'appId='+$.cookie("appId"));
            //分页操作
            var pager = $('#wechatRequestList').datagrid('getPager');
            if(pager){
                $(pager).pagination({
                    onSelectPage:function(pageNumber, pageSize){
                        $.cookie("pageNo", pageNumber, {expires:1});
                        loadWechatRequestList(pageSize, pageNumber, null, getPostData());
                    },
                    onRefresh:function(pageNumber, pageSize){
                        loadWechatRequestList(pageSize, pageNumber, null, getPostData());
                    },
                    onChangePageSize:function(pageSize){
                        $.cookie("pageSize", pageSize, {expires:1});
                        loadWechatRequestList(pageSize, 1, null, getPostData());
                    }
                })
            }
        });

        function getPostData() {
            var postData = $('#searchForm').serialize();
            var start = $('#startDate').datebox('getText');
            var end = $('#endDate').datebox('getText');
            if (start) {
                postData += '&startDate=' + start;
            }
            if (end) {
                postData += '&endDate=' + end;
            }

            return postData;
        }

        function searchList() {
            loadWechatRequestList($.cookie("pageSize"), 1, null, getPostData());
        }

        function loadWechatRequestList(pageSize, pageNo, successFun, condition) {
            var data = 'pageSize='+pageSize+'&pageNo='+pageNo;
            if(condition) {
                data = data + '&' + condition;
            }
            restClient('/rest/wechat/request/list', function(data){
                $('#wechatRequestList').datagrid("loadData", data);
                if(successFun) successFun();
            }, data);
        }

        function formatCreateTime(value, row, index) {
            if(row.createTime) {
                return new Date(row.createTime - (14 * 3600 * 1000)).Format("yyyy-MM-dd hh:mm:ss");
            }
        }

        function formatRespMsg(value, row, index) {
            if(row.respmsg) {
                return "<div title='" + row.respmsg + "' class='easyui-tooltip'>" + row.respmsg + "</a>";
            }
        }

        function formatEventkey(value, row, index) {
            if(row.eventkey) {
                return "<div title='" + row.eventkey + "' class='easyui-tooltip'>" + row.eventkey + "</a>";
            }
        }
    </script>
</head>
<body onload="isLogon();" style="width:100%;height:100%;margin: 0;">
<table id="wechatRequestList" class="easyui-datagrid" style="width:100%;height:100%;"
       toolbar="#toolbar" pagination="true"
       data-options="pageList:[10,15,20],pageSize:$.cookie('pageSize') ? $.cookie('pageSize') : 10"
       rownumbers="true" fitColumns="true" singleSelect="true">
    <thead>
    <tr>
        <th field="msgId" width="80">AppId</th>
        <th field="msgType" width="30" data-options="formatter:formatMsgType">消息类型</th>
        <th field="event" width="30">事件类型</th>
        <th field="eventkey" width="25" data-options="formatter:formatEventkey">事件Key</th>
        <th field="createTime" width="80" data-options="formatter:formatCreateTime">创建时间</th>
        <th field="content" width="100">文本内容</th>
        <th field="respmsg" width="200" data-options="formatter:formatRespMsg">应答消息</th>
        <!--<th field="id" width="20">查看</th>-->
    </tr>
    </thead>
</table>
<div id="toolbar">
    <form id="searchForm">
        AppId: <input class="easyui-combobox" id="appId" name="appId" style="width: 200px;"
                      data-options="valueField:'appId', textField:'description', formatter:formatAppId, editable:false">
        消息类型:
        <select class="easyui-combobox" name="msgType" data-options="editable:false">
            <option value="all">所有消息</option>
            <option value="text">文本消息</option>
            <option value="event">事件消息</option>
        </select>
        时间: <input id="startDate" class="easyui-datebox" data-options="editable:false,formatter:myformatter">
        至 <input id="endDate" class="easyui-datebox" data-options="editable:false,formatter:myformatter">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="searchList()">搜索</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-save" onclick="exportExcel()">导出</a>
    </form>
</div>

<script type="text/javascript">
    loadAppIdCombobox($('#appId'), true);

    function myformatter(date){
        var y = date.getFullYear();
        var m = date.getMonth()+1;
        var d = date.getDate();
        return y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d);
    }

    function exportExcel() {
        window.location.href = '/rest/wechat/request/exportExcel?' + getPostData();
    }
</script>
</body>
</html>